#define _CRT_SECURE_NO_WARNINGS 1


#include<stdlib.h>
#include<vector>
#include<iostream>

using namespace std;

int findClosestNumber(vector<int>& nums)
{
	int size = nums.size();
	int* arr = new int[size];
	int min = 999999;
	for (int i = 0; i < size; i++)
	{
		arr[i] = abs(nums[i]);
	}
	for (int i = 0; i < size; i++)
	{
		if (arr[i] < min)
		{
			min = arr[i];
		}
	}
	int max = min;
	for (int i = 0; i < size; i++)
	{
		if (arr[i] == min && nums[i] > max)
		{
			max = nums[i];
		}
	}
	return max;
}

int main()
{
	vector<int> v = { 2,-1,1 };
	cout << findClosestNumber(v) << endl;

	return 0;
}